<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>
<title>check-cast</title>
<link rel=stylesheet href="opcode.css">
</head>

<body>

<h1>check-cast</h1>

<h2>Purpose</h2>

<p>
Throw if the reference in the given register cannot be cast to the indicated
type. The type must be a reference type (not a primitive type). 
</p>

<h2>Details</h2>

<table class="instruc">
<thead>
<tr>
  <th>Op &amp; Format</th>
  <th>Mnemonic / Syntax</th>
  <th>Arguments</th>
</tr>
</thead>
<tbody>
<tr>
  <td>1f 21c</td>
  <td>check-cast vAA, type@BBBB</td>
  <td><code>A:</code> reference-bearing register (8 bits)<br/>
    <code>B:</code> type index (16 bits)</td>
</tr>
</tbody>
</table>

<h2>Constraints</h2>

<ul>
  <li>
    A must be a valid register index in the current stack frame.
  </li>
  <li>
    Register vA must contain a reference value.
  </li>
  <li>
    B must be a valid index into the type pool.
  </li>
  <li>
    Type pool entry B must contain a valid type descriptor for a reference type.
  </li>
</ul> 
    
<h2>Behavior</h2>

<ul>
  <li>
    An attempt is made to get a reference to the class C the name of which is
    contained in type pool entry B.
  </li>
  <li>
    If C has not been loaded and resolved before, it is being loaded and
    resolved. All exceptions that are possible during class loading can occur at
    this point.
  </li>
  <li>
    The run-time type of the object reference vA is compared against C.
    <ul>
      <li>
        If vA is null, the instruction succeeds (without further effects).
      </li>
      <li>
        If vA is assignment compatible with C according to the usual rules of
        the Java programming language, the instruction succeeds (without further
        effects).
      </li>
    </ul>
  </li>
</ul>

<h2>Exceptions</h2>

<ul>
  <li>
    ClassCastException is thrown if vA is either not null or not assignment
    compatible with C.
  </li>
</ul>

</body>
</html>
